﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;

namespace BLL
{
    public class ClassService : IService<Class>
    {
        TeacherDocsEntities db=new TeacherDocsEntities();
        public int Delete(Class t)
        {
           db.Entry(t).State=System.Data.Entity.EntityState.Deleted;
            return db.SaveChanges();
        }

        public int Inert(Class t)
        {
            var old=db.Class.ToList().FirstOrDefault(o=>o.Name==t.Name&& o.ClassNumber==t.ClassNumber&&o.Grade==t.Grade);
            if (old != null)
                return 0;

            db.Entry(t).State = System.Data.Entity.EntityState.Added;
            return db.SaveChanges();
        }

        public Class Select(int Id)
        {
           return db.Class.FirstOrDefault(x => x.Id == Id);
        }
        public List<Class> Select()
        {
            return db.Class.ToList();
        }

        public int Update(Class t)
        {
            db.Entry(t).State = System.Data.Entity.EntityState.Modified;
            return db.SaveChanges();
        }
    }
}
